﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CDB.LinqModel.Data;
using CDB.LinqData;
using CDB.LinqModel;

public partial class PropertyDetail : System.Web.UI.Page
{
    #region Variable Declration
    IDataRepository _dataObject = new DataRepository();
    Property property;
    PropertyImage pImage;
    List<PropertyImage> pImages = new List<PropertyImage>();
    #endregion

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["User"] == null)
                Response.Redirect("default.aspx");
            else
            {
                if (Request.QueryString["Id"] != null)
                {
                    fillBanners(Convert.ToInt32(Request.QueryString["Id"].ToString()));
                    fillProperty(Convert.ToInt32(Request.QueryString["Id"].ToString()));
                }
            }
        }
    }
    private void fillBanners(int propertyId)
    {
        pImage = new PropertyImage(_dataObject);
        pImages = pImage.GetAllPropertyImagesByPropertyId(propertyId);

        if (pImages != null)
        {
            for (int i = 0; i < pImages.Count; i++)
            {
                topbanners.InnerHtml += "<li><div class=\"bannerImage\"><img style='width:930px !important; height:303px !important;' src='PropertyImages/" + propertyId.ToString() + "/" + pImages[i].Name + "' /></div></li>";
            }
        }
    }
    private void fillProperty(int propertyId)
    {
        property = new Property(_dataObject);
        property.Id = propertyId;
        property.GetPropertyById();

        if (property.Id != 0)
        {
            dvDescription.InnerHtml = "<strong>Description:</strong><br />" + property.Description + "<hr /><strong>Features:</strong><br />" + property.Features;
            dvLeftPanel.InnerHtml = "<strong>Property Name:</strong><br />" + property.Name + "<hr /><strong>Address:</strong><br />" + property.Address1 + ",<br />" + property.Address2 + ",<br />" + property.City + "<hr /><strong>Year Built:</strong><br />" + property.YearBuilt + "<hr /><strong>Area in Sq.Mt:</strong><br />" + property.AreaSqMt + "<hr /><strong>Report:</strong><br />" + property.Report + "<hr /><strong>Issue:</strong><br />" + property.Issue;
        }
    }
}